package com.just.springbootmessage.activemq.m2;

import net.sf.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;

import javax.jms.JMSException;
import javax.jms.ObjectMessage;

/**
 * 监听某个消息队列
 */
@Component
public class M2Consumer {
    private Logger logger=LoggerFactory.getLogger(M2Consumer.class);
    @JmsListener(destination = "q1",containerFactory = "jmsListenerContainerQueue")
    public void receiverQueue(String msg){
        logger.info("consumer1接收到消息："+msg);
    }
    @JmsListener(destination = "q2",containerFactory = "jmsListenerContainerQueue")
    public void receiveObjectMsg(ObjectMessage objectMessage) throws JMSException {
        logger.info("consumer1收到对象信息："+objectMessage.getObject().toString());
        logger.info("转成json："+ JSONObject.fromObject(objectMessage.getObject()));
    }

    /**
     * 接收topic消息
     */
    @JmsListener(destination = "t1",containerFactory = "jmsListenerContainerTopic")
    public void receiverTopic1(String msg){
        logger.info("consumer1接收到topic消息："+msg);
    }
}
